//
//  TiDanChooseCarCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/15.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TiDanChooseCarCell.h"

@interface TiDanChooseCarCell ()

@property (nonatomic, strong) UILabel *numLab;
@property (nonatomic, strong) UILabel *driverLab;
@property (nonatomic, strong) UILabel *weightLab;
@property (nonatomic, strong) UILabel *volumeLab;
@property (nonatomic, strong) UIImageView *selectImgView;
@property (nonatomic, strong) UILabel *lineLab;

@end

@implementation TiDanChooseCarCell

+ (instancetype)TiDanChooseCarCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TiDanChooseCarCell";
    TiDanChooseCarCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TiDanChooseCarCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.numLab = [UILabel new];
        self.numLab.textColor = Color_ThemeColor;
        self.numLab.font = BoldFontOfSize(16);
        [self.contentView addSubview:self.numLab];
        
        self.driverLab = [UILabel new];
        self.driverLab.textColor = HexColor(0x585974);
        self.driverLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.driverLab];
        
        self.weightLab = [UILabel new];
        self.weightLab.textColor = HexColor(0x585974);
        self.weightLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.weightLab];
        
        self.volumeLab = [UILabel new];
        self.volumeLab.textColor = HexColor(0x585974);
        self.volumeLab.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.volumeLab];
        
        self.selectImgView = [UIImageView new];
        [self addSubview:self.selectImgView];
        
        self.lineLab = [UILabel new];
        self.lineLab.backgroundColor = Color_backgroundColor;
        [self.contentView addSubview:self.lineLab];
    }
    return self;
}

-(void)setModel:(TiDanChooseCarModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.numLab.text = self.model.num;
    [self.numLab sizeToFit];
    self.numLab.nim_left = 15;
    self.numLab.nim_top = 10;
    
    self.driverLab.text = [NSString stringWithFormat:@"司机：%@",self.model.driver_name];
    [self.driverLab sizeToFit];
    self.driverLab.nim_left = self.numLab.nim_right + 8;
    self.driverLab.nim_centerY = self.numLab.nim_centerY;
    
    self.weightLab.text = [NSString stringWithFormat:@"剩余装载重量(kg)：%@",self.model.remainWeight];
    [self.weightLab sizeToFit];
    self.weightLab.nim_left = self.numLab.nim_left;
    self.weightLab.nim_top = self.numLab.nim_bottom + 10;
    
    self.volumeLab.text = [NSString stringWithFormat:@"剩余装载体积(m³)：%@",self.model.remainVolume];
    [self.volumeLab sizeToFit];
    self.volumeLab.nim_left = self.numLab.nim_left;
    self.volumeLab.nim_top = self.weightLab.nim_bottom + 5;
    
    self.lineLab.frame = CGRectMake(15, self.volumeLab.nim_bottom + 10, ScreenW - 30, 1);
    
    self.selectImgView.frame = CGRectMake(ScreenW - 20 - 24, (self.lineLab.nim_top - 24) * 0.5, 24, 24);
    self.selectImgView.image = [UIImage imageNamed:self.model.isSelected ? @"icon_backBox_choice_sel" : @"icon_backBox_choice"];
    
    self.height = self.lineLab.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
